if(!jsx3.lang.Class.forName("ux.cdb.admin.contract.builder.step2.BaseInfo")) {
    jsx3.lang.Class.defineClass("ux.cdb.admin.contract.builder.step2.BaseInfo",
            ux.megatron.gui.WizardPanel,
            null,
            function (block) {
                /**
                 * instance initializer
                 * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
                 * @param vntLeft {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param vntTop {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param vntWidth {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param vntHeight {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
                 * @param strHTML {String} Text/HTML markup to place in the jsx3.gui.Block instance
                 */
                block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
                    //call constructor for super class (the super expects the name of the object and the function that it is an instance of)
                    this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
                };

                block.prototype.onAfterDeserialize = function() {
                    this.builder = this.getAncestorOfType("ux.cdb.admin.contract.builder.Builder");
                };

                block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    return this.doValidation() ? null : "NONE";
                };

                block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    this.detail = this.get("blkStep2");
                    this.wizard.appBasicInfo = this.detail.getDataAsObject();
                    this.displayTip(true);
                    return null; // return "NONE" to not advance panels
                };

                block.prototype.onStepJump =  function(objWIZARD, objSTEP, objEVENT, strCURRENTPANEL){
                    return this.doValidation() ? null : 'NONE'; //return "NONE" to cancel the current jumpping..
                };

                block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
                    this.builder.closeBuilder();
                    return null; // return "NONE" to not advance panels
                };

                block.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
                    if(this.doValidation()) { this.builder.saveBuilder(); }
                    return "NONE";
                };

                block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
                    if(!this.getChild(0)) {
                        var me = this;
                        ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin",
                            "ux/cdb/admin/contract/builder/step2/ui/baseInfoContent.xml", me, me.initialize);
                    } else {
                        this.initialize();
                    }
                    return null; // return "NONE" to not advance panels
                };

                block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
                    return null; // return "NONE" to not advance panels
                };

                block.prototype.initialize = function() {
                    var me = this;
                    this.wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
                    this.builder = this.getAncestorOfType("ux.cdb.admin.contract.builder.Builder");
                    this.detail = this.get("blkStep2");
                    if(!this.loaded) {

                        //Load options of listbox
                        ux.cdb.admin.CommonCache.loadCache(['CONTRACT_STATUS','CURRENCY','INT_RATE_TYPE','REPAY_MODE','CERT_TYPE'], this, function(){
                            var cache = ux.cdb.admin.CommonCache.getInstance();
                            me.get("blkFieldState").get("selValue").setSourceXML(cache.getCache("CommonCache_CONTRACT_STATUS"));
                            me.get("blkFieldState").get("selValue").repaint();
                            me.get("blkFieldMoneyType").get("selValue").setSourceXML(cache.getCache("CommonCache_CURRENCY"));
                            me.get("blkFieldMoneyType").get("selValue").repaint();
                            me.get("blkFieldInterestType").get("selValue").setSourceXML(cache.getCache("CommonCache_INT_RATE_TYPE"));
                            me.get("blkFieldInterestType").get("selValue").repaint();
                            me.get("repayModeCode").get("selValue").setSourceXML(cache.getCache("CommonCache_REPAY_MODE"));
                            me.get("repayModeCode").get("selValue").repaint();
                            me.get("fieldOfTypeCodeName").get("selValue").setSourceXML(cache.getCache("CommonCache_CERT_TYPE"));
                            me.get("fieldOfTypeCodeName").get("selValue").repaint();
                        });
                        
                        //Set dialog title for different entries
                        if(this.builder.comeFrom == 'LoanManage') {
                            this.builder.get("windowBar").setText(ux.megatron.Main.getServer().getDynamicProperty("@cdb@contractBuilder@dialogTitleSign"), true);
                            var parent = ux.megatron.Main.getServer().getBodyBlock();
                            this.wizard.newAppBasicInfo = parent.newAppBasicInfo;
                        } else {
                            this.builder.get("windowBar").setText(ux.megatron.Main.getServer().getDynamicProperty("@cdb@contractBuilder@dialogTitleDelete"), true);                      
                        }

                        //Set current date as initial value of required DateUpdater 
                        var cIter = this.detail.getAllConsumersIterator();
                        while(cIter.hasNext()) {
                            var updater = cIter.next();
                            if(updater instanceof ux.cdb.admin.dataautomate.DateUpdater) {
                                if(updater.isRequired() && !updater.get("dateValue").getDate()) {
                                    updater.get("dateValue").setDate(new Date());
                                }
                            }
                        }
						this.get('appPeriodStartDate').get('dateValue').setDate(new Date());
						try{
							var educationSysCode = parseInt(this.wizard.curSchoolingInfo.educationSysCode);
							var gradeCode = parseInt(this.wizard.curSchoolingInfo.gradeCode);
							jsx3.log('educationSysCode['+educationSysCode+'], gradeCode['+gradeCode+']');
							var _appLimitPeriod = educationSysCode - gradeCode + 1 + 2;
							this.wizard.newAppBasicInfo['appLimitPeriod'] = _appLimitPeriod;
							//this.get('appLimitPeriod').get('txtValue').setValue(_appLimitPeriod, true);
							var __d = new Date();
							var _endYear = __d.getFullYear() + _appLimitPeriod;
							var _endDate = new Date(_endYear, 7, 31);
							this.get('appPeriodMaturityDate').get('dateValue').setDate(_endDate);
						}catch(e){/* alert(e.message) */}

                        //Speical validation for Amount6000
                        this.get("blkFieldLoanAmount").validateAmount6000 = function(val) {
                            if(ux.megatron.util.ValidationManager.isPositiveNumeric(val) &&
                                    (val >= 1000 && val <= 6000)) {
                                return null;
                            }
                            return ux.megatron.Main.getServer().getDynamicProperty("@cdb@contract@ValidationAmount10006000");
                        };

                        var intValidation = function(val) {
                            if(ux.megatron.util.ValidationManager.isPositiveFloatingPoint(val) &&
                                   (val >= 0 && val <= 100)) {
                                return null;
                            }
                            return ux.megatron.Main.getServer().getDynamicProperty("@cdb@contract@ValidationInterest");
                        };

                        this.get("signDate").validateLTToday = function(val) {
                            if((val instanceof Date) && val > (new Date())) {
                                return ux.megatron.Main.getServer().getDynamicProperty("@cdb@contract@ValidationLTToday");
                            }
                            return null;
                        };
                        
                        //Remove
                        /*
                        this.get("nextIntRateAdjustDate").validateGTToday = function(val) {
                            if((val instanceof Date) && val <= (new Date())) {
                                return ux.megatron.Main.getServer().getDynamicProperty("@cdb@contract@ValidationGTToday");
                            };
                            return null;
                        };
                        */

                        this.get("appMaturityDate").validateEndDay1 = function(val) {
                            if((val instanceof Date) && val < me.get("appStartDate").getData()) {
                                return ux.megatron.Main.getServer().getDynamicProperty("@cdb@contract@ValidationEndDay1");
                            }
                            return null;
                        };

                        this.get("appPeriodMaturityDate").validateEndDay2 = function(val) {
                            if((val instanceof Date) && val < me.get("appPeriodStartDate").getData()) {
                                return ux.megatron.Main.getServer().getDynamicProperty("@cdb@contract@ValidationEndDay2");
                            }
                            return null;
                        };

                        this.get("intRateFloatingRange").validateInterest = intValidation;
                        this.get("appBenchIntRate").validateInterest = intValidation;

                        this.detail.addRule(["appBenchIntRate", "intRateFloatingRange"], ["appContractInt"], function(o, t) {
                            var amt1 = parseFloat(o[0].getData(), 10);
                            var amt2 = parseFloat(o[1].getData(), 10);
                            if(!isNaN(amt1) && !isNaN(amt2)) {
                                t[0].setSimpleData(amt1*(1+amt2));
                            }
                        });

                        this.detail.addRule(["appStartDate", "appPeriod"], ["appMaturityDate"], function(o, t) {
                            var val1 = o[0].getData();
                            var val2 = parseInt(o[1].getData(), 10);
                            var ret;
                            if(val1 instanceof Date && !isNaN(val2)) {
                                ret = new Date(val1.getFullYear()+val2, 7, 31);
                                t[0].setSimpleData(ret);
                            }
                        });
                        this.detail.addRule(["appPeriodStartDate", "appLimitPeriod"], ["appPeriodMaturityDate"], function(o, t) {
                            var val1 = o[0].getData();
                            var val2 = parseInt(o[1].getData(), 10);
                            var ret;
                            if(val1 instanceof Date && !isNaN(val2)) {
                                ret = new Date(val1.getFullYear()+val2, val1.getMonth(), val1.getDate());
                                t[0].setSimpleData(ret);
                            }
                        });
                    }

                    this.loaded = true;
                    if(this.wizard.editMode == "Edit") {
                        this.wizard.get("buttonPrev").disable();
                        delete this.buttonStatesArr;
                        this.buttonStates="buttonPrev:DISABLED";
                    }
                    if(this.wizard.appBasicInfo) {
                        this.detail.setDataByObject(this.wizard.appBasicInfo);
                    } else if(this.wizard.newAppBasicInfo) {
                        //console.log(this.wizard.newAppBasicInfo);
                        var serverData = {};
                        for(i in this.wizard.newAppBasicInfo) {
                            serverData[i] = this.wizard.newAppBasicInfo[i];
                        }
                        serverData.appStatusCode = serverData.appStatusCode || "02";
                        serverData.intRateFloatingRange = serverData.intRateFloatingRange || "0";
                        //serverData.appCurrencyCode = serverData.appCurrencyCode || "CNY";
                        serverData.appCurrencyCode = "CNY";
                        //serverData.appIntRateTypeCode = serverData.appIntRateTypeCode || "01";
                        serverData.appIntRateTypeCode = "01";
                        //
                        serverData.repayModeCode = "01";
						if(!serverData.appBenchIntRate) serverData.appBenchIntRate = '7.83';
						if(!serverData.appContractInt) serverData.appContractInt = '7.83';

                        var defaultNextIntRateAdjustDate = new Date((new Date()).getFullYear(), 11, 21);
                        if(defaultNextIntRateAdjustDate<new Date()) {
                            defaultNextIntRateAdjustDate = new Date((new Date()).getFullYear()+1, 11, 21);
                        }
                        serverData.nextIntRateAdjustDate = serverData.nextIntRateAdjustDate || defaultNextIntRateAdjustDate;
                        serverData.certTypeCodeName = this.wizard.certTypeCodeName;
                        try{
                            //console.log(serverData["approveStartDate"]);
                            if(!serverData["approveStartDate"]){
                                serverData["approveStartDate"] = new Date();
                            }
                            //console.log(serverData["approveStartDate"]);
                            if(serverData["appPeriod"] && !serverData["approveMaturityDate"]){
                                serverData["approveMaturityDate"] = new Date(serverData["approveStartDate"].getFullYear() + serverData["appPeriod"], 7, 31);
                            };
                            this.detail.setDataByObject(serverData);
                        } catch(ex) {
                            console.log(ex);
                        }
                        console.log(this.get("appStartDate").get("dateValue").getDate());
                        var _setIntRateType = function(){
                            if(me.get("blkFieldInterestType").get("selValue").getValue()){
                                try{
                                    if(me.get("blkFieldState").get("selValue").getValue() == 97){
                                        me.get("blkFieldState").get("selValue").setValue("02");
                                    }
                                    me.get("blkFieldInterestType").get("selValue").setValue("02");
                                    me.get("appBenchIntRate").get("txtValue").setValue("7.83");
                                } catch(ex){
                                }
                            } else {
                                console.log("NOT READY");
                                setTimeout(_setIntRateType, 100);
                            }
                        };
                        _setIntRateType();
                    }
                };
                block.prototype.displayTip = function(passed, tip) {
                    if(!passed) {
                        tip = tip || ux.megatron.Main.getServer().getDynamicProperty("@cdb@contractBuilder@TipUnFinishedStep2");
                        this.wizard.getMessageLabel().setText(tip).repaint();
                    } else {
                        this.wizard.getMessageLabel().setText("");
                    }
                    return passed;
                };

                block.prototype.doValidation = function() {
                    var errorMsgs = this.detail.doValidate();
                    this.detail = this.get("blkStep2");
                    if(errorMsgs === null) {
                        this.wizard.appBasicInfo = this.detail.getDataAsObject();
						console.log('this.wizard.appBasicInfo : \n', this.wizard.appBasicInfo);
                        return this.displayTip(true);
                    } else {
                        var tip = errorMsgs[0].label ? errorMsgs[0].label + ":" + errorMsgs[0].message : errorMsgs[0].message;
                        return this.displayTip(false, tip);
                    }
                };
            }
    );
}
